package com.jsd2412.backend.meals.service.impl;

import com.jsd2412.backend.mealGroups.pojo.entity.MealGroups;
import com.jsd2412.backend.meals.mapper.MealsMapper;
import com.jsd2412.backend.meals.pojo.dto.MealSaveParam;
import com.jsd2412.backend.meals.pojo.dto.MealsQueryParam;
import com.jsd2412.backend.meals.pojo.entity.Meals;
import com.jsd2412.backend.meals.pojo.vo.MealsVO;
import com.jsd2412.backend.meals.service.MealsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class MealsServiceImpl implements MealsService {
    @Autowired
    private MealsMapper mealsMapper;

    @Override
    public List<MealsVO> select(MealsQueryParam mealsQueryParam) {
        log.debug("查询膳食业务:{}", mealsQueryParam);
        Meals meals=new Meals();
        BeanUtils.copyProperties(mealsQueryParam,meals);
        List<MealsVO> list = mealsMapper.select(meals);
        return list;
    }

    @Override
    public void save(MealSaveParam mealSaveParam) {
        log.debug("保存膳食业务:{}", mealSaveParam);
        Meals meals=new Meals();
        BeanUtils.copyProperties(mealSaveParam,meals);
        if (meals.getId()==null){
            meals.setCreateTime(new Date());
            log.debug("新增膳食业务:{}",meals);
            mealsMapper.insert(meals);
        }else {
            meals.setUpdateTime(new Date());
            log.debug("修改膳食业务:{}",meals);
            mealsMapper.update(meals);
        }

    }

    @Override
    public void delete(Long id) {
         mealsMapper.delete(id);
         log.debug("删除膳食业务:{}",id);
    }
}
